<template>
  <div class="app-container">
    <!-- <div class="filter-container">
      <el-button
        class="filter-item"
        type="primary"
        size="small"
        icon="el-icon-circle-plus"
        @click="$router.push(add_url)"
        >添加</el-button
      >
    </div> -->
    <el-table
      :data="tableData"
      v-loading="loadList"
      element-loading-text="拼命加载中..."
      border
    >
      <el-table-column prop="name" label="名称"></el-table-column>
      <el-table-column prop="image" label="图片" width="100px">
        <template slot-scope="scope">
          <img :src="scope.row.image" style="width: 50px; height: 50px" />
        </template>
      </el-table-column>
      <el-table-column prop="jifen" label="积分"></el-table-column>
      <el-table-column prop="probability" label="中奖比例"></el-table-column>
    
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <el-button size="mini" @click="edit(scope.row.id)">修改</el-button>
         
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getList, del } from "./api/index";
export default {
  data() {
    return {
      loadList: true,
      tableData: [],
      // getListFunc: Service.getList,
      // delItemFunc: Service.delItem,
      add_url: "/prize-proportion/add",
      edit_url: (id) => {
        return `/prize-proportion/${id}/edit`;
      },
    };
  },
  created() {
    this.refresh_data();
  },
  methods: {
    // 获取置顶卡列表
    refresh_data() {
      getList()
        .then((data) => {
          console.log(data, "=====");
          if (data.code === 1) {
            this.tableData = data.data;
          } else {
            this.$message.error(data.description);
            this.currentPage = 1;
          }
          this.loadList = false;
        })
        .catch((err) => {
          console.log(err);
          this.loadList = false;
        });
    },
    edit(id) {
      this.$router.push(this.edit_url(id));
    },
    async del(item) {
      this.loadList = true;
      const res = await del(item);
      if (res.code === 1) {
        this.refresh_data();
      } else {
        this.$message.error(res.msg);
      }
    },
  },
};
</script>

<style scoped>
</style>
